<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/base/pages/base.jsp" %>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>list</title>
</head>
<body>
<table id="dg" class="easyui-datagrid" title="Row Editing in DataGrid" style="width:700px;height:auto"
			data-options="				
				iconCls: 'icon-edit',
				singleSelect: true,
				title:'应用系统列表',   
				nowrap: false,   
		        striped: true,   
		        border: true, 
				toolbar: '#tb',
				url: '<%=path %>/hellselectStestByVal.action',
				//sortName: 'code',   
        		//sortOrder: 'desc', 
				rownumbers:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
			">
		<thead>
			<tr>
				<th data-options="field:'id',width:80">Item ID</th>
				<th data-options="field:'name',width:100,
						formatter:function(value,row){
							return row.name;
						}">Product</th>
				<th data-options="field:'listprice',width:80,align:'right'">List Price</th>
				<th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="padding:5px;height:auto">
		<div>
			id: <input name="id"/>
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchData()">Search</a>
		</div>
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">增加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="edit()">修改</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="del()">删除</a>
		</div>
	</div>

	<div id="dlg" class="easyui-dialog" style="width:400px;height:210px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle">User Information</div>
		<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>id:</label>
				<input name="st.id" id="stid" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>Name:</label>
				<input name="st.name" id="stname" class="easyui-validatebox" required="true">
			</div>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">确定</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	</div>
	<script type="text/javascript">
		$(function($) {
			var queryParams = {};
			$('#dlg').dialog('close');
			//设置分页控件   
			$('#dg').datagrid({ 
				queryParams:{},     
				onLoadSuccess:function(){   
	                $('#dg').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题   
	            },   
                onBeforeLoad: function(){   
                  if(queryParams){   
                      $('#dg').datagrid('options').queryParams = {};   
                  }   
                }    
	        });   

		    var p = $('#dg').datagrid('getPager'); 
		    $(p).pagination({   
		        pageSize: 10,//每页显示的记录条数，默认为10   
		        pageList: [5,10,15],//可以设置每页记录条数的列表   
		        beforePageText: '第',//页数文本框前显示的汉字   
		        afterPageText: '页    共 {pages} 页',   
		        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',   
		        /*onBeforeRefresh:function(){  
		            $(this).pagination('loading');  
		            alert('before refresh');  
		            $(this).pagination('loaded');  
		        }*/  
		    }); 

		});
		function searchData(){
			var name = $("input[name=id]").val();   	        
             queryParams = $('#dg').datagrid('options').queryParams;   
             queryParams.condoName = name;   
             $('#dg').datagrid('load',{ 
            	 id:name
             }); 
		}
		function append(){ 
			$('#dlg').dialog('open').dialog('setTitle','新增');
			$('#fm').form('clear');
			url = '<%=path %>/helladdStest.action';
		}
		function saveUser(){
			$('#fm').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(vresult){	
					var result=$.parseJSON(vresult);
					if (result.resultStr=="保存成功"||result.resultStr=="更新成功"){
						$.messager.show({
							title:'info',
							msg: result.resultStr
						});
						$('#dlg').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.resultStr
						});
					} 
				}
			});
		}
		function edit(){
			var row = $('#dg').datagrid('getSelected');
			if (row==null){
				$.messager.confirm('确认框', '请选择要修改的记录?');  
			}else{
				$('#dlg').dialog('open').dialog('setTitle','修改');
				//$('#fm').form('load',row);
				$("#stid").val(row.id);
				$("#stname").val(row.name);
				url = '<%=path %>/hellupdateStest.action';
			}
		}
		function del(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.confirm('确认框', '请选择要删除的记录?', function(r){   
	                if (r){   
	                	$.post('<%=path %>/helldelStest.action',{id:row.id},function(result){
							if (result.resultStr.indexOf("成功")>-1){
								$.messager.show({
									title:'info',
									msg: result.resultStr
								});
								$('#dg').datagrid('reload');	// reload the user data
							} else {
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.resultStr
								});
							}
						},'json'); 
	                }   
	           });  
			}
		}
	</script>
</body>
</html>、